﻿/*
	Copyright (C) 2019 Zongming Liu <1849059316@qq.com>

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License along
	with this program; if not, write to the Free Software Foundation, Inc.,
	51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include <cstdlib>
#include <string.h>
#include <string>
#include "utility.h"
#include <exception>
#include <cstdio>
#include <errno.h>
#include "../win32/ApplicationView.h"
#include "../base/GameWorld.h"

namespace SkyEngine2d
{
	
	void checkFailed(HRESULT hr)
	{
		if (FAILED(hr))
		{
			auto err = GetLastError();
			char buf[128]{};
			sprintf_s(buf, sizeof(buf),"发生运行时错误!\n");
			throw std::exception(buf);
		}
	}
	
	void checkFailed(HRESULT hr, const char * file_reason)
	{
		if (FAILED(hr))
		{
			throw std::exception(file_reason);
		}
	}
	
	Vector2 convertToRenderCoordinateVector2(const Vector2 & pos)
	{
		auto size = GameWorld::getInstance()->getAppView()->getViewSize();
		return Vector2(pos.x, size.height - pos.y);
	}
	
}
